package com.hy.erp.inventory.service;

import java.util.LinkedList;
import java.util.List ;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;



import com.hy.enterprise.architecture.foundation.ArchitectureFoundationException;
import com.hy.enterprise.framework.service.business.AbstractBusinessService;
import com.hy.erp.inventory.dao.PositionDao;
import com.hy.erp.inventory.dao.PositionTypeDao;
import com.hy.erp.inventory.dao.interfaces.IPositionDao;
import com.hy.erp.inventory.dao.interfaces.IUserDao;
import com.hy.erp.inventory.pojo.PositionType;
import com.hy.erp.inventory.pojo.Position;
import com.hy.erp.inventory.pojo.interfaces.IPosition;
import com.hy.erp.inventory.pojo.interfaces.IUser;
import com.hy.erp.inventory.service.interfaces.IPositionService;
import com.hy.erp.inventory.service.interfaces.IPositionTypeService;

/**
 * 
 * <ul>
 * <li>开发作者：汤莉</li>
 * <li>设计日期：2010-10-13；时间：下午12:00:16</li>
 * <li>类型名称：PositonService</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订编号：</b>
 * <li>修订日期：</li>
 * <li>修订作者：</li>
 * <li>修订原因：</li>
 * <li>修订内容：</li>
 * </ul>
 */
//@Name("positonTypeService")
//@Component("positonTypeService")
@Component("positionService")
public class PositionService extends AbstractBusinessService <PositionDao>	implements	IPositionService
{

	/**
	 * <ul>
	 * <li>开发作者：汤莉</li>
	 * <li>设计日期：2010-10-13；时间：下午12:00:11</li>
	 * <li>字段类型：long；字段名称：serialVersionUID</li>
	 * <li>设计目的：</li>
	 * </ul>
	 * <ul>
	 * <b>修订编号：</b>
	 * <li>修订日期：</li>
	 * <li>修订作者：</li>
	 * <li>修订原因：</li>
	 * <li>修订内容：</li>
	 * </ul>
	 */
	private static final long	serialVersionUID	=
														4135821211971078891L ;
	/**
	 * 
	 * 构造函数
	 */
	public PositionService()
	{
		super ( );
	}

	private PositionDao positionDao=null;
	
	@Resource(name="positionDao")
	public void setPositionTypeDao(PositionDao positionDao) {
		this.positionDao = positionDao;
	}
	
	@ Override
	public boolean addPosition (
								Position positon )
	{
		if(positon==null)
		{
			return true;
		}
		else
		{
			//IPositonDao dao=( IPositonDao ) this.getDao ( IPositon.class );
			//IPositon iPositon= positon;
			//return dao.persist ( iPositon ) ;
			return positionDao.persist ( positon ) ;
		}
	}

	@ Override
	public Integer removePosition (
									String [ ] Ids )
	{
		if ((null == Ids) || (Ids.length == 0)) {
			return new Integer(0);
		} else {
			//IPositonDao dao = (IPositonDao) this.getDao(IPositon.class);
			//return dao.remove(Ids);
			return positionDao.remove(Ids);
		}
	}

	@ SuppressWarnings ( "unused" )
	@ Override
	public boolean modifyPosition (
									Position positon )
	{
		if ( ( null == positon ) || ( null == positon.getIdentifier ( ) ))
		{
			return true;
		}
		else
		{
			//IPositonDao dao=( IPositonDao ) this.getDao ( IPositon.class );
			//IPositon iPositon= positon;
			
			if ( null == positon )
			{
				throw new ArchitectureFoundationException (
				                                            "修改用户实体数据时发生错误，所需要修改的实体在数据库中并不存在" ) ;
			}
			return (positionDao.merge ( positon )!=null) ;
		}
	}

	@ Override
	public String [ ] addPosition (
									Object [ ] objects )
	{
		//IPositonDao dao=( IPositonDao ) this.getDao ( IPositon.class );
		Position[] positons=new Position[objects.length];
		for ( int i =
						0 ; i < objects.length ; i ++ )
		{
			Position positon=( Position ) objects[i];
			positons[i]=positon;
		}
//		return dao.persist ( positons ) ;
		return positionDao.persist ( positons ) ;
	}

	@ Override
	public List < Position > getAllPosition ( )
	{
		//IPositonDao dao=( IPositonDao ) this.getDao ( IPositon.class );
//		return dao.find ( ) ;
		List < Position > list= positionDao.find ( ) ;
		List < Position > list2= new LinkedList<Position>();
		for (Position positon : list) {
			positon.set("NAME"+"ForShow", positon.get("NAME"));
			positon.set("ForShow", "fasdfffffff");
			positon.set("ForShowd22", "sdddddddddddd");
			PositionType positionType = positon.getPositonType();
			positionType.set("NAME"+"ForShow", positionType.get("NAME"));
			positon.setPositonType(positionType);
			list2.add(positon);

		}
		return list2 ;

	}

	@Override
	public String[] modifyPosition(Object[] objects) {
		// TODO Auto-generated method stub
		return null;
	}

	/*@ Override
	public String [ ] modifyPositon (
										Object [ ] objects )
	{
		if (  null == objects ) 
		{
			return null;
		}
		else
		{
			//IPositonDao dao=( IPositonDao ) this.getDao ( IPositon.class );
			Positon[] types=new Positon[objects.length];
            for(int i=0;i<objects.length;i++)
            {
            	Positon type=( Positon ) objects[i];
            	types[i]=type;
            }
			
			return positionDao.merge ( types );
		}
	}*/

}
